package com.tang.crm.controller;

import com.tang.crm.base.BaseController;
import com.tang.crm.base.ResultInfo;
import com.tang.crm.dto.CustomerLossDto;
import com.tang.crm.entity.CustomerLoss;
import com.tang.crm.service.CustomerLossService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.Map;

/**
 * 客户流失管理
 * @author SHIRELY阳
 */
@Controller
@RequestMapping("/customer_loss")
public class CustomerLossController extends BaseController {

    @Autowired
    private CustomerLossService customerLossService;

    /**
     * 进入客户流失管理页面
     * @return
     */
    @RequestMapping("/index")
    public String index(){
        return "customerLoss/customer_loss";
    }

    /**
     * 分特查询流失客户
     * @param customerLossDto
     * @return
     */
    @RequestMapping("/list")
    @ResponseBody
    public Map<String, Object> selectByParams(CustomerLossDto  customerLossDto){
        return customerLossService.selectByParams(customerLossDto);
    }

    /**
     * 打开添加暂缓/详情页面
     * @param lossId
     * @param model
     * @return
     */
    @RequestMapping("/toCustomerLossPage")
    public String toCustomerLossPage(Integer lossId, Model model){
        // 通过流失客户的ID查询对应流失客户的记录
        CustomerLoss customerLoss = customerLossService.getById(lossId);
        // 将流失客户对应的数据存到请求域中
        model.addAttribute("customerLoss", customerLoss);
        return "customerLoss/customer_rep";
    }

    /**
     * 更新流失客户的流失状态
     * @param id
     * @param lossReason
     * @return
     */
    @RequestMapping("/updateCustomerLossStateById")
    public ResultInfo updateCustomerLossStateById(Integer id, String lossReason) {
        customerLossService.updateCustomerLossStateById(id, lossReason);
        return success("确认流失成功");
    }
}
